package vip.idiy.anwei_android_iot.adapters;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import vip.idiy.anwei_android_iot.R;
import vip.idiy.anwei_android_iot.domin.mqtt.SwitchTypeData;

/**
 * ClassName RecyclerViewSwitchAdapter
 * describe: 开关适配
 * Created: 勇
 * Email:118085890@qq.com
 * Version: 1.0
 * Create in 20:35 2023/4/28
 */
public class RecyclerViewSwitchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final String TAG = "myTag " + " RecyclerViewSwitchAdapter ";
    private List<SwitchTypeData> switchTypeDataList;

    public RecyclerViewSwitchAdapter(List<SwitchTypeData> switchTypeDataList) {
        this.switchTypeDataList = switchTypeDataList;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_switch_item, parent, false);
        return new SwitchBasicHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        SwitchBasicHolder switchHolder = (SwitchBasicHolder) holder;
        SwitchTypeData switchTypeData = switchTypeDataList.get(position);
        switchHolder.icon_image_view.setImageResource(switchTypeData.isStatus() ? R.mipmap.icon_switch_on : R.mipmap.icon_switch_off);
        switchHolder.name_text_view.setText(switchTypeData.getSwitchName());
    }

    @Override
    public int getItemCount() {
        return switchTypeDataList.size();
    }


    public class SwitchBasicHolder extends RecyclerView.ViewHolder {
        ImageView icon_image_view;
        TextView name_text_view;


        public SwitchBasicHolder(@NonNull View itemView) {
            super(itemView);
            icon_image_view = itemView.findViewById(R.id.icon_image_view);
            name_text_view = itemView.findViewById(R.id.name_text_view);
        }
    }
}
